<?php
function get_parent_ecosystems($return_array = FALSE) {
  $query = 'select id, ecosystem_type from win_ecosystems where parent_id is NULL';
  $result = db_query($query);
  if (!$result) {
    if ($return_array) {
      return FALSE;
    }
    else {
      die(json_encode(set_error_arr("Error talking to database.")));
    }
  }
  else {
    $ecosystems = array();
    while ($obj = db_fetch_object($result)) {
      $ecosystems[$obj->id] = $obj->ecosystem_type;
    }
    
    if ($return_array) {
      return $ecosystems;
    }
    else {
      $response = set_no_error_arr("");
      $response['ecosystems'] = $ecosystems;
      die(json_encode($response));
    }
  }
}

function get_child_ecosystems($parent_id, $return_array = FALSE) {
  $query = 'select id, ecosystem_type from win_ecosystems where parent_id = %d';
  $query_args = array($parent_id);
  $result = db_query($query, $query_args);
  if (!$result) {
    if ($return_array) {
      return FALSE;
    }
    else {
      die(json_encode(set_error_arr("Error talking to database.")));
    }
  }
  else {
    $ecosystems = array();
    while ($obj = db_fetch_object($result)) {
      $ecosystems[$obj->id] = $obj->ecosystem_type;
    }    

    if ($return_array) {
      return $ecosystems;
    }
    else {
      $response = set_no_error_arr("");
      $response['ecosystems'] = $ecosystems;
      die(json_encode($response));
    }
  }
}